<?php

namespace Admin\Controller;
//use Think\Controller;
use SoftDelete;

class MemberController extends CommonController
{
    public function index()
    {
        $member = M('member');

        $where = [];

        if(I('get.sex') != '') {
            $where['sex'] = I('get.sex');
        }

        if(I('get.keywords')) {
            $where['name'] = ['LIKE', '%'.I('get.keywords').'%'];
        }

        $count = $member->where($where)->count(); // 获取符合当前条件的条数

        $Page = new \Think\Page($count, 2); // 调用TP自带的分页类 Page(总条数, 每页条数)
        $this->assign('page', $Page->show()); // 通过 show() 方法生产分页HTML，并赋值


        $memberList = $member->where($where)->limit($Page->firstRow, $Page->listRows)->select();

        $this->assign('memberList',$memberList);

        $data = M('member')->select();
        //var_dump($data);exit;
        $this->assign('data',$data);
        $this->display();  
    }

     /*
			处理修改提交的数据
		 */
        public  function  edit()
        {
            //地址栏get到uid
            $id = I('get.uid');
            //var_dump($id);exit;
            //var_dump($uid);
        //   $data = M('bbs_user')->find($uid);
        //     var_dump($data);die;
        //  使用M方法查询表里面并且找一条.数据
           $data = M('member')->find($id);
        //    var_dump($data);die;
    
           //分配变量
           $this->assign('data',$data);
           //展示页面
            $this->display();
        }


		public function update(){
			//实例化模型类
			$m = M('member');
            //var_dump($m);die;
			//接收数据
			$uid = I('post.id');
			$data = I('post.');		//获取所有要修改的数据
            unset($data['id']);	//去掉主键
            
            //保存新数据
			$res = $m->where(['id'=>$id])->save($data);

			if($res === false){
				$this->error('修改失败');
			}
			$this->success('修改成功',U('member/index'));
}
public function delete()
{
    $id = I('get.uid');
    //var_dump($id);die;

    //$data = M()->table('bbs_user')->where(['uid' =>$uid])->find();
    $ma = M('member');
     //var_dump($ma);
     $info = $ma->where("id = {$id}")->find();
     
         //var_dump($info);die;

    $res =  $ma->delete($id);
    // var_dump($data);
   
    if($res === false){
        $this->error('删除失败');
    }else
    $this->success('删除成功',U('member/index'));
}
}